<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Dair.File</title>
<link href="css/File.css" rel="stylesheet" type="text/css"></link>
<script>
djConfig={
	isDebug:true, 				// true debugs to Console or terminal, false, no output
	parseOnLoad: false, 
	airConfig:{
		terminal:false,			// logs to terminal window, does not open Console
		debuggerKey:119,		// the keyCode that opens the Console (doesn't really work)
		introspectorKey:118, 	// the keyCode that opens the Console 
		showTimestamp:false,	// whether to show a timestamp on every line
		showSender:false		// whether to show the file on every line
	}
}

</script>
<script src="../js/dojo/dojo.js"></script>
<script>

dojo.require("dair.AIR");
dojo.require("dair.File");
dojo.require("dijit.form.Button");


editor = {
	init: function(){
		this.file = new dair.File();
		this.domNode = dojo.byId("myDoc");
		this.statusNode = dojo.byId("statusBar");
		this.titleNode = dojo.byId("titleBar");
		this.textBox = dojo.byId("textBox");
		this.enable(false);
		dojo.connect(this.file, "onError", this, function(evt){
			this.status("ERROR-"+evt.type.toUpperCase()+": "+evt.message);
		});
		dojo.connect(this.file, "onDelete", this, function(evt){
			this.status("File deleted");
			this.domNode.value = "";
			this.enable(false);
		});
		this.connect("onNewFile", "New file created");
		this.connect("onOpen", "File open");
		this.connect("onSave", "File saved");
		this.connect("onSaveAs", "Saving file...");
		this.connect("onBrowse", "Select...");
		this.connect("onCopy", "File copied");
		this.connect("onMove", "File moved");
		this.connect("onDelete", "File deleted");
		
		this.status("Ready to begin");
	},
	connect: function(func, msg){
		dojo.connect(this.file, func, this, function(){
			this.status(msg);
		});
	},
	status: function(str){
		this.statusNode.innerHTML = str;
		this.titleNode.innerHTML = this.file.getFullName();
	},
	newFile: function(){
		this.close();
		this.file.newFile();
		this.enable(true);
	},
	open: function(path){
		this.file.open(path).addCallback(this, function(str){
			this.enable(true);
			this.domNode.value = str;
		});
	},
	saveAs: function(){
		this.file.saveAs(this.domNode.value);
	},
	save: function(){
		this.file.save(this.domNode.value);
	},
	copyTo:function(){
		this.file.copyTo();
	},
	moveTo: function(){
		this.file.moveTo();
	},
	remove: function(){
		this.file.remove();
	},
	close: function(){
		this.domNode.value = "";
		this.file.close();
		this.enable(false);
	},
	
	enable:function(enabled){
		if(enabled){
			dojo.attr(this.domNode, "disabled", false);
			dojo.addClass(this.textBox, "enabled");
		}else{
			dojo.attr(this.domNode, "disabled", true);
			dojo.removeClass(this.textBox, "enabled");
		}
	}
}

dojo.addOnLoad(function(){dojo.require("dair.File");
	editor.init();
});
</script>
</head>

<body class="tundra">
<h1>Dair.File</h1>
<div id="titleBar">My Title</div>
<div id="textBox">
<textarea id="myDoc"></textarea>
</div>
<button onClick="editor.newFile();" dojoType="dijit.form.Button">New</button>
<button onClick="editor.open();" dojoType="dijit.form.Button">Open</button>
<button onClick="editor.save();" dojoType="dijit.form.Button">Save</button>
<button onClick="editor.saveAs();" dojoType="dijit.form.Button">Save As</button>
<button onClick="editor.close()" dojoType="dijit.form.Button">Close</button>
<button onClick="editor.copyTo()" dojoType="dijit.form.Button">Copy To</button>
<button onClick="editor.moveTo()" dojoType="dijit.form.Button">Move To</button>
<button onClick="editor.remove()" dojoType="dijit.form.Button">Delete</button>
<div id="statusBar">status....</div>
</body>
</html>
